//
//  ShuaWordItemCell.m
//  Learn
//
//  Created by apple on 2024/4/18.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "ShuaWordItemCell.h"
#import "ShuaWordModel.h"

@interface ShuaWordItemCell ()
/* <#描述#> */
@property (nonatomic, strong) UIView    * bgView;
@property (nonatomic, strong) UILabel    * titleLabel;
@property (nonatomic, strong) UIImageView    * stateImg;

@end

@implementation ShuaWordItemCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
- (void)createUI {
    [self.contentView addSubview:self.bgView];
}
- (UIView *)bgView {
    if(!_bgView){
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0 , (SCREEN_W - 31)/2.0f,50)];
        _bgView.backgroundColor = [UIColor whiteColor];
        [_bgView js_setRoundedCorners:UIRectCornerAllCorners radii:5];
        [_bgView addSubview:self.titleLabel];
        [_bgView addSubview:self.stateImg];
    }
    return _bgView;
}
- (UILabel *)titleLabel {
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.bgView.width, self.bgView.height)];
        _titleLabel.text = @"";
        _titleLabel.textColor = rgbHex(0x666666, 1);
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}
- (UIImageView *)stateImg {
    if(!_stateImg){
        _stateImg = [[UIImageView alloc]initWithFrame:CGRectMake(self.bgView.width - 29, 0, 18,18)];
        _stateImg.centerY = self.titleLabel.centerY;
        _stateImg.contentMode = UIViewContentModeScaleAspectFill;
        _stateImg.image = [UIImage imageNamed:@"addIcon"];
        _stateImg.hidden = YES;
    }
    return _stateImg;
}
- (void)setIsChoose:(BOOL)isChoose {
    _isChoose = isChoose;
}

- (void)updateItemCellModel:(id)ItemModel {
    if ([ItemModel isKindOfClass:ShuaWordModel.class]) {
        ShuaWordModel *model = (ShuaWordModel *)ItemModel;
        self.stateImg.hidden = !self.isChoose;
        self.titleLabel.text = model.words_detail.words;

        if (model.isSelect) {
            self.stateImg.image = [UIImage imageNamed:@"rightIcon"];
        }else{
            self.stateImg.image = [UIImage imageNamed:@"addIcon"];

        }
    }
}
@end
